package com.atmaowei.controller;

import com.atmaowei.common.Result;
import com.atmaowei.controller.request.TeacherOfTeacherPageRequest;
import com.atmaowei.entity.Teacher;
import com.atmaowei.service.TeacherOfTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/teacherOfTeacher")
public class TeacherOfTeacherController {

    @Autowired
    private TeacherOfTeacherService teacherOfTeacherService;

    @GetMapping("/page")
    public Result page(TeacherOfTeacherPageRequest teacherOfTeacherPageRequest) {
        return Result.success(teacherOfTeacherService.page(teacherOfTeacherPageRequest));
    }

    @GetMapping("/getCourse/{tno}")
    public Result getCourse(@PathVariable String tno) {
        return Result.success(teacherOfTeacherService.getCourse(tno));
    }

    @GetMapping("/getTeacherInfo/{tno}")
    public Result getTeacherInfo(@PathVariable String tno) {
        return Result.success(teacherOfTeacherService.getTeacherInfo(tno));
    }

    @PutMapping("/update")
    public Result update(@RequestBody Teacher teacher) {
        teacherOfTeacherService.update(teacher);
        return Result.success();
    }

    @GetMapping("/checkPassword/{tno}/{password}")
    public Result checkPassword(@PathVariable String tno, @PathVariable String password) {
        if (teacherOfTeacherService.checkPassword(tno, password)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @PutMapping("/updatePassword/{tno}/{password}")
    public Result updatePassword(@PathVariable String tno, @PathVariable String password) {
        teacherOfTeacherService.updatePassword(tno, password);
        return Result.success();
    }

    @PutMapping("/giveGrade/{sno}/{cno}/{tno}/{grade}")
    public Result giveGrade(@PathVariable String sno, @PathVariable String cno, @PathVariable String tno, @PathVariable String grade) {
        teacherOfTeacherService.giveGrade(sno, cno, tno, grade);
        return Result.success();
    }

}
